home *** CD-ROM | disk | FTP | other *** search
- Path: news.sprintlink.net!datalytics!usenet
- From: Rob Stewart <stew@datalytics.com>
- Newsgroups: comp.lang.c++
- Subject: Re: URGENT..Help Needed!!
- Date: Tue, 26 Mar 1996 20:07:02 -0500
- Organization: Datalytics, Inc
- Message-ID: <315894B6.6A78@datalytics.com>
- References: <4j0h0u$9dj$1@sydney.DIALix.oz.au>
- NNTP-Posting-Host: 204.62.224.71
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0 (WinNT; I)
-
- A and K Gonzalez wrote:
- > My main questions are how do initialise an array to zero or set them with
- > spaces?
- > Assuming you are using a character array, and are not using a
- class to encapsulate the vector (array) behavior, try this:
-
- #include <string.h> // memcpy
-
- char* p = new char[MAX_LENGTH];
- memcpy(
- p,
- 0, // or ' '
- MAX_LENGTH);
-
- > How can I search through my arrays looking for a space in them? Do I use
- > a while loop??
- > Using the array allocated above:
-
- #include <stddef.h> // size_t
-
- for (size_t i = 0; i < MAX_LENGTH; i++)
- {
- if (p[i] == ' ') // if found a space
- {
- // do whatever is important when you find it
- break; // if find only one
- }
- }
-
- > And lastly, how do I list all items in the array, one per line??
- > #include <iostream.h> // cout
-
- for (size_t i = 0; i < MAX_LENGTH; i++)
- {
- cout << "p[" << i << "] == " << p[i] << endl;
- }
-
- --
- Robert Stewart | My opinions are usually my own.
- Datalytics, Inc. | stew@datalytics.com
-